package com.yj.ccs.abs.common.service;

import com.yj.ccs.abs.common.Constants;
import com.yj.ccs.abs.util.encryption.Digests;
import com.yj.ccs.abs.util.encryption.Encodes;
import org.springframework.stereotype.Service;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/14
 * Author     : Unbelievable9
 **/
@Service
public class PasswordService {

    /**
     * 验证密码是否正确
     *
     * @param password      哈希加密后密码
     * @param password_salt 密码盐
     * @param plainPassword 原始密码
     * @return 密码是否正确
     */
    public Boolean isValidPassword(String password, String password_salt, String plainPassword) {
        String credential = Encodes.encodeHex(
                Digests.sha1(plainPassword.getBytes(),
                        Encodes.decodeHex(password_salt),
                        Constants.HASH_ITERATION_COUNT));

        return credential.equals(password);
    }
}
